<!DOCTYPE html><html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
<meta charset="utf-8">
<title>phpDocumentor » \ActiveRecord\CallBack</title>
<meta name="author" content="Mike van Riel">
<meta name="description" content="">
<link href="../css/template.css" rel="stylesheet" media="all">
<script src="../js/jquery-1.7.1.min.js" type="text/javascript"></script><script src="../js/jquery-ui-1.8.2.custom.min.js" type="text/javascript"></script><script src="../js/jquery.mousewheel.min.js" type="text/javascript"></script><script src="../js/bootstrap.js" type="text/javascript"></script><script src="../js/template.js" type="text/javascript"></script><script src="../js/prettify/prettify.min.js" type="text/javascript"></script><link rel="shortcut icon" href="../img/favicon.ico">
<link rel="apple-touch-icon" href="../img/apple-touch-icon.png">
<link rel="apple-touch-icon" sizes="72x72" href="../img/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="114x114" href="../img/apple-touch-icon-114x114.png">
</head>
<body>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner"><div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></a><a class="brand" href="../index.html">phpDocumentor</a><div class="nav-collapse"><ul class="nav">
<li class="dropdown">
<a href="#api" class="dropdown-toggle" data-toggle="dropdown">
                                    API Documentation <b class="caret"></b></a><ul class="dropdown-menu">
<li><a>Packages</a></li>
<li><a href="../packages/ActiveRecord.html"><i class="icon-folder-open"></i> ActiveRecord</a></li>
<li><a href="../packages/Default.html"><i class="icon-folder-open"></i> Default</a></li>
</ul>
</li>
<li class="dropdown" id="charts-menu">
<a href="#charts" class="dropdown-toggle" data-toggle="dropdown">
                                    Charts <b class="caret"></b></a><ul class="dropdown-menu"><li><a href="../graph_class.html"><i class="icon-list-alt"></i> Class hierarchy diagram</a></li></ul>
</li>
<li class="dropdown" id="reports-menu">
<a href="#reports" class="dropdown-toggle" data-toggle="dropdown">
                                    Reports <b class="caret"></b></a><ul class="dropdown-menu">
<li><a href="../errors.html"><i class="icon-remove-sign"></i> Errors 
                <span class="label label-info">310</span></a></li>
<li><a href="../markers.html"><i class="icon-map-marker"></i> Markers 
                <ul><li>todo 
                <span class="label label-info">5</span>
</li></ul></a></li>
<li><a href="../deprecated.html"><i class="icon-stop"></i> Deprecated elements 
                <span class="label label-info">3</span></a></li>
</ul>
</li>
</ul></div>
</div></div>
<div class="go_to_top"><a href="#___" style="color: inherit">Back to top  <i class="icon-upload icon-white"></i></a></div>
</div>
<div id="___" class="container">
<noscript><div class="alert alert-warning">
                            Javascript is disabled; several features are only available
                            if Javascript is enabled.
                        </div></noscript>
<div class="row">
<div class="span4">
<span class="btn-group visibility" data-toggle="buttons-checkbox"><button class="btn public active" title="Show public elements">Public</button><button class="btn protected" title="Show protected elements">Protected</button><button class="btn private" title="Show private elements">Private</button><button class="btn inherited active" title="Show inherited elements">Inherited</button></span><div class="btn-group view pull-right" data-toggle="buttons-radio">
<button class="btn details" title="Show descriptions and method names"><i class="icon-list"></i></button><button class="btn simple" title="Show only method names"><i class="icon-align-justify"></i></button>
</div>
<ul class="side-nav nav nav-list">
<li class="nav-header">
<i class="icon-custom icon-method"></i> Methods
                    <ul>
<li class="method public "><a href="#method___construct" title="__construct :: Creates a CallBack."><span class="description">Creates a CallBack.</span><pre>__construct()</pre></a></li>
<li class="method public "><a href="#method_get_callbacks" title="get_callbacks :: Returns all the callbacks registered for a callback type."><span class="description">Returns all the callbacks registered for a callback type.</span><pre>get_callbacks()</pre></a></li>
<li class="method public "><a href="#method_register" title="register :: Register a new callback."><span class="description">Register a new callback.</span><pre>register()</pre></a></li>
</ul>
</li>
<li class="nav-header">
<i class="icon-custom icon-property"></i> Properties
                    <ul></ul>
</li>
<li class="nav-header protected">» Protected
                    <ul><li class="property protected "><a href="#property_VALID_CALLBACKS" title="$VALID_CALLBACKS :: List of available callbacks."><span class="description"></span><pre>$VALID_CALLBACKS</pre></a></li></ul>
</li>
<li class="nav-header private">» Private
                    <ul>
<li class="property private "><a href="#property_klass" title="$klass :: Container for reflection class of given model"><span class="description"></span><pre>$klass</pre></a></li>
<li class="property private "><a href="#property_publicMethods" title="$publicMethods :: List of public methods of the given model"><span class="description"></span><pre>$publicMethods</pre></a></li>
<li class="property private "><a href="#property_registry" title="$registry :: Holds data for registered callbacks."><span class="description"></span><pre>$registry</pre></a></li>
</ul>
</li>
</ul>
</div>
<div class="span8">
<a id="\ActiveRecord\CallBack"></a><ul class="breadcrumb">
<li>
<a href="../index.html"><i class="icon-custom icon-class"></i></a><span class="divider">\</span>
</li>
<li><a href="../namespaces/ActiveRecord.html">ActiveRecord</a></li>
<li class="active">
<span class="divider">\</span><a href="../classes/ActiveRecord.CallBack.html">CallBack</a>
</li>
</ul>
<div class="element class">
<p class="short_description">Callbacks allow the programmer to hook into the life cycle of a {@link Model}.</p>
<div class="details">
<div class="long_description"><p>You can control the state of your object by declaring certain methods to be
called before or after methods are invoked on your object inside of ActiveRecord.</p>

<p>Valid callbacks are:</p>

<ul>
<li><b>after_construct:</b> called after a model has been constructed</li>
<li><b>before_save:</b> called before a model is saved</li>
<li><b>after_save:</b> called after a model is saved</li>
<li><b>before_create:</b> called before a NEW model is to be inserted into the database</li>
<li><b>after_create:</b> called after a NEW model has been inserted into the database</li>
<li><b>before_update:</b> called before an existing model has been saved</li>
<li><b>after_update:</b> called after an existing model has been saved</li>
<li><b>before_validation:</b> called before running validators</li>
<li><b>after_validation:</b> called after running validators</li>
<li><b>before_validation_on_create:</b> called before validation on a NEW model being inserted</li>
<li><b>after_validation_on_create:</b> called after validation on a NEW model being inserted</li>
<li><b>before_validation_on_update:</b> see above except for an existing model being saved</li>
<li><b>after_validation_on_update:</b> ...</li>
<li><b>before_destroy:</b> called after a model has been deleted</li>
<li><b>after_destroy:</b> called after a model has been deleted</li>
</ul>

<p>This class isn't meant to be used directly. Callbacks are defined on your model like the example below:</p>

<pre><code>class Person extends ActiveRecord\Model {
  static $before_save = array('make_name_uppercase');
  static $after_save = array('do_happy_dance');

  public function make_name_uppercase() {
    $this->name = strtoupper($this->name);
  }

  public function do_happy_dance() {
    happy_dance();
  }
}
</code></pre>

<p>Available options for callbacks:</p>

<ul>
<li><b>prepend:</b> puts the callback at the top of the callback chain instead of the bottom</li>
</ul></div>
<table class="table table-bordered">
<tr>
<th>package</th>
<td><a href="../packages/ActiveRecord.html">ActiveRecord</a></td>
</tr>
<tr>
<th>link</th>
<td><a href="http://www.phpactiverecord.org/guides/callbacks">http://www.phpactiverecord.org/guides/callbacks</a></td>
</tr>
</table>
<h3>
<i class="icon-custom icon-method"></i> Methods</h3>
<a id="method___construct"></a><div class="element clickable method public method___construct" data-toggle="collapse" data-target=".method___construct .collapse">
<h2>Creates a CallBack.</h2>
<pre>__construct(string $model_class_name) : CallBack</pre>
<div class="labels"></div>
<div class="row collapse"><div class="detail-description">
<div class="long_description"></div>
<h3>Parameters</h3>
<div class="subelement argument">
<h4>$model_class_name</h4>
<code>string</code><p>The name of a {@link Model} class</p>
</div>
<h3>Returns</h3>
<div class="subelement response"><code>CallBack</code></div>
</div></div>
</div>
<a id="method_get_callbacks"></a><div class="element clickable method public method_get_callbacks" data-toggle="collapse" data-target=".method_get_callbacks .collapse">
<h2>Returns all the callbacks registered for a callback type.</h2>
<pre>get_callbacks($name) : array</pre>
<div class="labels"></div>
<div class="row collapse"><div class="detail-description">
<div class="long_description"></div>
<h3>Parameters</h3>
<div class="subelement argument">
<h4>$name</h4><p>string Name of a callback (see {@link VALID_CALLBACKS $VALID_CALLBACKS})</p>
</div>
<h3>Returns</h3>
<div class="subelement response">
<code>array</code>array of callbacks or null if invalid callback name.</div>
</div></div>
</div>
<a id="method_register"></a><div class="element clickable method public method_register" data-toggle="collapse" data-target=".method_register .collapse">
<h2>Register a new callback.</h2>
<pre>register(string $name, mixed $closure_or_method_name, array $options) : void</pre>
<div class="labels"></div>
<div class="row collapse"><div class="detail-description">
<div class="long_description"><p>The option array can contain the following parameters:</p>

<ul>
<li><b>prepend:</b> Add this callback at the beginning of the existing callbacks (true) or at the end (false, default)</li>
</ul></div>
<h3>Parameters</h3>
<div class="subelement argument">
<h4>$name</h4>
<code>string</code><p>Name of callback type (see {@link VALID_CALLBACKS $VALID_CALLBACKS})</p>
</div>
<div class="subelement argument">
<h4>$closure_or_method_name</h4>
<code>mixed</code><p>Either a closure or the name of a method on the {@link Model}</p>
</div>
<div class="subelement argument">
<h4>$options</h4>
<code>array</code><p>Options array</p></div>
<h3>Exceptions</h3>
<table class="table table-bordered"><tr>
<th><code><a href="../classes/ActiveRecord.ActiveRecordException.html">\ActiveRecord\ActiveRecordException</a></code></th>
<td>if invalid callback type or callback method was not found</td>
</tr></table>
</div></div>
</div>
<h3>
<i class="icon-custom icon-property"></i> Properties</h3>
<a id="property_VALID_CALLBACKS"> </a><div class="element clickable property protected property_VALID_CALLBACKS" data-toggle="collapse" data-target=".property_VALID_CALLBACKS .collapse">
<h2></h2>
<pre>$VALID_CALLBACKS : array</pre>
<div class="labels"></div>
<div class="row collapse"><div class="detail-description"><div class="long_description"></div></div></div>
</div>
<a id="property_klass"> </a><div class="element clickable property private property_klass" data-toggle="collapse" data-target=".property_klass .collapse">
<h2></h2>
<pre>$klass : object</pre>
<div class="labels"></div>
<div class="row collapse"><div class="detail-description"><div class="long_description"></div></div></div>
</div>
<a id="property_publicMethods"> </a><div class="element clickable property private property_publicMethods" data-toggle="collapse" data-target=".property_publicMethods .collapse">
<h2></h2>
<pre>$publicMethods : array</pre>
<div class="labels"></div>
<div class="row collapse"><div class="detail-description"><div class="long_description"></div></div></div>
</div>
<a id="property_registry"> </a><div class="element clickable property private property_registry" data-toggle="collapse" data-target=".property_registry .collapse">
<h2></h2>
<pre>$registry : array</pre>
<div class="labels"></div>
<div class="row collapse"><div class="detail-description"><div class="long_description"></div></div></div>
</div>
</div>
</div>
</div>
</div>
<div class="row"><footer class="span12">
            Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
            Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a12</a> and<br>
            generated on 2013-06-08T13:56:18-04:30.<br></footer></div>
</div>
</body>
</html>
